package com.xbongbong.pro.statistics.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.toolbox.util.I18nUtil;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.statistic.result.pojo.vo.ChartResultDetailVO;
import com.xbongbong.pro.statistics.service.StarDataService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述信息
 *
 * @ClassName TestController
 * @Author 梁鲁江
 * 创建时间 2022/8/29 19:09
 * 修改时间  2022/8/29 19:09
 **/
@RestController
@RequestMapping(value = XbbProConstant.API_ROOT_PREFIX + "/ck/agg")
public class TestController {
    @Resource
    private StarDataService starDataService;
    @RequestMapping(value = "/result", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String ckResult(@RequestBody BaseDTO baseDTO, BindingResult br) {
        XbbResponse<ChartResultDetailVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            // feign调用后国际化处理
            LocaleContextHolder.setLocale(I18nUtil.getLocale(baseDTO.getLocale()));
            List lllll = starDataService.findListMapBySql("select * from tb_saas_customer   LIMIT 1");
            System.out.println(lllll);
            ChartResultDetailVO  chartResultDetailVO = new ChartResultDetailVO();
            response = new XbbResponse<>(chartResultDetailVO);
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

}
